<?php

class Page {

  // Create required variables
  var $Title;
  var $MetaDescription;
  var $MetaKeywords;
  var $Content;
  var $ThisPage;

  // Standard page template
  function Template() {
    require_once('../config.php');
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    echo "\n";
    echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
    echo '<head profile="http://gmpg.org/xfn/11">';
    echo "\n";
    echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    echo "\n";
    $this->DisplayTitle();
    echo "\n";
    $this->DisplayMetaDescription();
    echo "\n";
    $this->DisplayMetaKeywords();
    echo "\n";
    //echo '<link rel="stylesheet" href="style.css" type="text/css" media="screen" />';
    //TG 19/7/09
    require_once('./admin/theme/maintheme.php');
    echo "\n";
    echo '</head>';
    echo "\n";
    echo '<body>';   // ================= start body ========== 
    echo "\n\n";
    echo '<div id="wrap">';
    echo "\n";
    echo '	<div id="header">';
    //TG 19/7/09
    require_once('./includes/header.php'); 
    echo '</div>';
    echo "\n";
    echo '	<div id="content">';
    echo "\n\n";
	echo $this->Content;
    $le_page = $this->ThisPage; // For navigation menu
	 //echo $le_page. " xx";
    echo "\n	</div><!-- content_eof //-->\n";
    echo '	<div id="navigation">';
    echo "\n\n";
    echo '<ul id="menu">';
    echo "\n";
    if ($this->ThisPage == "index") {
      echo '<li><strong>Home Page</strong></li>';
    } else {
      echo '<li><a href="'.$wwwroot. '/" title="Home Page">Home Page</a></li>';
    }
    echo "\n";
    //TG 19/7/09
    include ('./classes/makebutton.class.php');
    //TG 19/7/09
    include ('./includes/menu.php');
    echo '<li><a href="'.$wwwroot. '/cms/favorites/favorites.php" title="Favourites">Favourites</a></li>';
    echo '<li><a href="'.$wwwroot. '/contact.php" title="Contact">Contact</a></li>';
    echo "\n</ul>\n\n";
    echo '	</div><!-- navigation_eof //-->';
    echo "\n";
    echo '	<div id="extra">';
    echo "\n\n";
    //TG 19/7/09
    include ('./includes/extra.php');
    echo "\n\n";
    echo '	</div><!-- extra_eof //-->';
    echo "\n";
    echo '	<div id="search">';
    echo "\n\n";
    //TG 19/7/09
    include ('./includes/searchform.php');
    echo "\n\n";
    echo '	</div><!-- search_eof //-->';
    echo "\n";
    echo '	<div id="footer">';
    echo "\n\n";
    echo '<p>';
    //TG
    include ('./includes/footer.php');
    echo "</p>\n\n";
    include ('./includes/tracking.php');
    echo "\n	</div><!-- footer_eof //-->\n";
    echo '</div><!-- wrap_eof //-->';
    echo "\n\n</body>\n</html>\n";
  }

  function DisplayTitle() {
    echo "<title>" . $this->Title . "</title>";
  }

  function DisplayMetaDescription() {
    echo '<meta name="description" content="' . $this->MetaDescription . '" />';
  }

  function DisplayMetaKeywords() {
    echo '<meta name="keywords" content="' . $this->MetaKeywords . '" />';
  }

  function DisplayThisPage() {
    echo $this->ThisPage;
  }
//  Original 
//  function SetContent($Data) {
//    $this->Content = $Data;
//  }

  function SetContent($cat) {
	if (strpos($cat,"ategories/") == 1){ //Image category type
		if (!file_exists($cat)) {
			$this->Content = "Category File: " .$cat ." not found.";
		}else{
			$this->Content = "";
			$imgtxtarray = file($cat);  //load imgtxtarray array
			foreach($imgtxtarray as $name){
				$name=trim($name);
				$imgtxt = "imgtxt/" .$name .".txt";
				if (!file_exists($imgtxt)){
					$this->Content = $this->Content ."No " .$imgtxt ." found.<br />";
				}else{			
					$file_contents = file_get_contents($imgtxt);
					if (strlen(trim($file_contents))==0){					
						$file_contents = $name;
					}
					$file_contents = autop($file_contents, 0);
					$file_contents = convert_chars($file_contents, 0);
					$this->Content = $this->Content .$file_contents;
				}
				unset($tmparray);
				exec("ls -1 imgtxt/ |grep -F " .$name ." |grep -Fv .txt ",$tmparray);
				if (!isset($tmparray[0])){
					$this->Content = $this->Content ."No image file with name: " .$name ." found.";
				}else{
					$cnt=0;
					foreach($tmparray as $val){
						if (strpos($val,$name .".") === 0 && $cnt == 0){
							$this->Content = $this->Content ."<br /><img src=\"imgtxt/" .$val ."\" alt=\"" .$name ."\" title=\"" .$name ."\" /><br />";
							$cnt++;
						}
					}
					if ($cnt==0){
						$this->Content = $this->Content ."No image file with name: " .$name ." found.";
					}
				}
			}  
		}	
	}else{   //No Image category type (original type
		$this->Content = $cat;
	} // End of if 

  } // End of function
}  // End of Class 
?>
